import request from '@/utils/request'

/**
 * 裁判管理API接口
 */

// 分页查询裁判列表
export function getRefereePage(currentPage, pageSize, queryParams) {
  return request({
    url: `/api/referees/page/${currentPage}/${pageSize}`,
    method: 'get',
    params: queryParams
  })
}

// 根据ID查询裁判详情
export function getRefereeById(refereeId) {
  return request({
    url: `/api/referees/${refereeId}`,
    method: 'get'
  })
}

// 新增裁判
export function addReferee(refereeData) {
  return request({
    url: '/api/referees',
    method: 'post',
    data: refereeData
  })
}

// 更新裁判信息
export function updateReferee(refereeData) {
  return request({
    url: '/api/referees',
    method: 'put',
    data: refereeData
  })
}

// 删除裁判
export function deleteReferee(refereeId) {
  return request({
    url: `/api/referees/${refereeId}`,
    method: 'delete'
  })
}

// 批量删除裁判
export function batchDeleteReferees(refereeIds) {
  return request({
    url: '/api/referees/batch',
    method: 'delete',
    data: refereeIds
  })
}

// 更新裁判状态
export function updateRefereeStatus(refereeId, status) {
  return request({
    url: `/api/referees/${refereeId}/status`,
    method: 'put',
    params: { status }
  })
}

// 分配裁判到项目
export function assignRefereeToProject(assignmentData) {
  return request({
    url: '/api/referees/assign',
    method: 'post',
    data: assignmentData
  })
}

// 接受分配
export function acceptAssignment(assignmentId) {
  return request({
    url: `/api/referees/assignments/${assignmentId}/accept`,
    method: 'put'
  })
}

// 拒绝分配
export function rejectAssignment(assignmentId, reason) {
  return request({
    url: `/api/referees/assignments/${assignmentId}/reject`,
    method: 'put',
    params: { reason }
  })
}

// 获取裁判分配列表
export function getRefereeAssignments(refereeId, queryParams) {
  return request({
    url: `/api/referees/${refereeId}/assignments`,
    method: 'get',
    params: queryParams
  })
}

// 取消分配
export function cancelAssignment(assignmentId) {
  return request({
    url: `/api/referees/assignments/${assignmentId}/cancel`,
    method: 'put'
  })
}

// 获取裁判统计信息
export function getRefereeStatistics() {
  return request({
    url: '/api/referees/statistics',
    method: 'get'
  })
}

// 获取裁判执裁记录
export function getRefereeRecords(refereeId, queryParams) {
  return request({
    url: `/api/referees/${refereeId}/records`,
    method: 'get',
    params: queryParams
  })
}

// 获取裁判执裁历史
export function getRefereeHistory(refereeId, queryParams) {
  return request({
    url: `/api/referees/${refereeId}/history`,
    method: 'get',
    params: queryParams
  })
}

// 自动分配裁判
export function autoAssignReferees(projectId, assignmentConfig) {
  return request({
    url: `/api/referees/auto-assign/${projectId}`,
    method: 'post',
    data: assignmentConfig
  })
}

// 推荐裁判
export function recommendReferees(projectId, queryParams) {
  return request({
    url: `/api/referees/recommend/${projectId}`,
    method: 'get',
    params: queryParams
  })
}

// 激活裁判身份
export function activateReferee(refereeId, activationData) {
  return request({
    url: `/api/referees/${refereeId}/activate`,
    method: 'put',
    data: activationData
  })
}

// 停用裁判身份
export function deactivateReferee(refereeId, reason) {
  return request({
    url: `/api/referees/${refereeId}/deactivate`,
    method: 'put',
    params: { reason }
  })
}

// 获取裁判资质等级列表
export function getRefereeLevels() {
  return request({
    url: '/api/referees/levels',
    method: 'get'
  })
}

// 更新裁判资质等级
export function updateRefereeLevel(refereeId, levelId, certificateData) {
  return request({
    url: `/api/referees/${refereeId}/level`,
    method: 'put',
    data: { levelId, ...certificateData }
  })
}

// 根据项目查询可用裁判
export function getAvailableRefereesForProject(projectId, queryParams) {
  return request({
    url: `/api/referees/available/${projectId}`,
    method: 'get',
    params: queryParams
  })
}

// 根据专长查询裁判
export function getRefereesBySpecialty(specialty, queryParams) {
  return request({
    url: '/api/referees/by-specialty',
    method: 'get',
    params: { specialty, ...queryParams }
  })
}

// 根据资质等级查询裁判
export function getRefereesByLevel(levelId, queryParams) {
  return request({
    url: '/api/referees/by-level',
    method: 'get',
    params: { levelId, ...queryParams }
  })
}

// 查询裁判工作负载
export function getRefereeWorkload(refereeId, queryParams) {
  return request({
    url: `/api/referees/${refereeId}/workload`,
    method: 'get',
    params: queryParams
  })
}

// 批量导入裁判
export function importReferees(file) {
  const formData = new FormData()
  formData.append('file', file)

  return request({
    url: '/api/referees/import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 导出裁判数据
export function exportReferees(queryParams) {
  return request({
    url: '/api/referees/export',
    method: 'get',
    params: queryParams,
    responseType: 'blob'
  })
}

// 导出裁判执裁记录
export function exportRefereeRecords(refereeId, queryParams) {
  return request({
    url: `/api/referees/${refereeId}/records/export`,
    method: 'get',
    params: queryParams,
    responseType: 'blob'
  })
}

// 获取裁判评分
export function getRefereeRatings(refereeId, queryParams) {
  return request({
    url: `/api/referees/${refereeId}/ratings`,
    method: 'get',
    params: queryParams
  })
}

// 提交裁判评分
export function submitRefereeRating(ratingData) {
  return request({
    url: '/api/referees/rating',
    method: 'post',
    data: ratingData
  })
}

// 获取裁判工作时间统计
export function getRefereeWorkTimeStats(refereeId, queryParams) {
  return request({
    url: `/api/referees/${refereeId}/work-time-stats`,
    method: 'get',
    params: queryParams
  })
}

// 更新裁判联系方式
export function updateRefereeContact(refereeId, contactData) {
  return request({
    url: `/api/referees/${refereeId}/contact`,
    method: 'put',
    data: contactData
  })
}

// 验证裁判资质证书
export function verifyRefereeCertificate(refereeId, certificateData) {
  return request({
    url: `/api/referees/${refereeId}/verify-certificate`,
    method: 'post',
    data: certificateData
  })
}

// 获取裁判证书列表
export function getRefereeCertificates(refereeId) {
  return request({
    url: `/api/referees/${refereeId}/certificates`,
    method: 'get'
  })
}

// 上传裁判证书
export function uploadRefereeCertificate(refereeId, certificateData) {
  return request({
    url: `/api/referees/${refereeId}/certificate`,
    method: 'post',
    data: certificateData
  })
}

// 删除裁判证书
export function deleteRefereeCertificate(refereeId, certificateId) {
  return request({
    url: `/api/referees/${refereeId}/certificate/${certificateId}`,
    method: 'delete'
  })
}

// 获取裁判当前分配状态
export function getRefereeCurrentAssignments(refereeId) {
  return request({
    url: `/api/referees/${refereeId}/current-assignments`,
    method: 'get'
  })
}

// 更新裁判可用时间
export function updateRefereeAvailability(refereeId, availabilityData) {
  return request({
    url: `/api/referees/${refereeId}/availability`,
    method: 'put',
    data: availabilityData
  })
}

// 获取裁判可用时间
export function getRefereeAvailability(refereeId, queryParams) {
  return request({
    url: `/api/referees/${refereeId}/availability`,
    method: 'get',
    params: queryParams
  })
}